package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type appConfig struct {
	Mysql
	Redis
}

type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}
type Redis struct {
	Host     string
	Port     int
	Password string
	Database int
}

var Config appConfig

func Init() {
	var err error
	viper.SetConfigFile("appconfig/dev.yaml") //设置配置文件路径

	err = viper.ReadInConfig() //读取配置文件

	if err != nil {
		panic(err)
	}
	err = viper.Unmarshal(&Config) //映射到结构体变量
	if err != nil {
		panic(err)
	}
	fmt.Println("config:", Config)
	fmt.Println("config init success")

	//log.Printf("config: init success %+v", Config)
	//log.Printf("config: init success")
}
